const express = require('express')
const cors = require('cors')
const axios = require('axios')
const app = express()
const port = 3001

app.use(cors())

app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
// 登录
app.get('/getUserFullInfo', (req, res) => {
  let {gids} = req.query
  axios({
    method:'GET',
    url: 'https://bbs-api.mihoyo.com/user/wapi/getUserFullInfo',
    params: {
      gids: gids
    }
  }).then(response => {
    res.send(response.data)
  })
})
// table
app.get('/getForumsByGameForPHP', (req, res) => {
  let {gids} = req.query
  axios({
    method:'GET',
    url: `https://bbs-api-static.mihoyo.com/forum/wapi/getForumsByGameForPHP`,
    params: {
      gids: gids
    }
  }).then(response => {
    res.send(response.data)
  })
})
// 首页
app.get('/webHome', (req, res) => {
  let {gids,page,page_size} = req.query
  axios({
    method:'GET',
    url: `https://bbs-api-static.mihoyo.com/apihub/wapi/webHome`,
    params: {
      gids,
      page,
      page_size
    }
  }).then(response => {
    res.send(response.data)
  })
})

app.get('/getDynamicData', (req, res) => {
  let {gids,post_ids} = req.query
  axios({
    method:'GET',
    url: `https://bbs-api.mihoyo.com/post/wapi/getDynamicData`,
    params: {
      gids,
      post_ids
    }
  }).then(response => {
    res.send(response.data)
  })
})
// 推荐
app.get('/recommendActive', (req, res) => {
  let {gids,page_size} = req.query
  axios({
    method:'GET',
    url: `https://bbs-api.mihoyo.com/user/wapi/recommendActive`,
    params: {
      gids,
      page_size
    }
  }).then(response => {
    res.send(response.data)
  })
})

app.listen(port, () => {
  console.log(`localhost:${port}`)
})
